// pages/companyVideos.js
const app = getApp()
var page = 1;
var selectedNews = false;
var newsList = [];

Page({

  /**
   * 页面的初始数据
   */
  data: {
    Videos: [],
    video_id:''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    
  },
  // 视频播放,暂停是一个视频
  startPlayVideo: function (e) {
    // 本视频id
    var id = e.currentTarget.id;
    // 上个一视频id
    var prev_id = this.data.video_id;
    // 停止山一个视频播放
    if (id != prev_id) {
      wx.createVideoContext(prev_id).pause();
      this.setData({
        video_id: id
      })
    }
  },
  //公司视频,
  getGoodsList: function () {
    var that = this;
    var url = '/platform_api/news';
    var params = {
      uid: app.globalData.SwitchTabParams.v_id,
      type: 1,
      pageno: page,
      pagesize: 10
    };
    app.HttpPostSend(url, params, function (res) {
      if (res.msg != "success") {
        app.showTipMsg(res.msg);
        selectedNews = false;
        that.setData({
          Videos: []
        })
      } else {
        var goods = res.data;
        for (var i = 0; i < goods.length; i++) {
          newsList.push(goods[i]);
        }
        if (goods.length < 10) {
          selectedNews = false;
        } else {
          selectedNews = true;
          page += 1;
        }
        that.setData({
          Videos: newsList
        })
        wx.hideLoading();
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    page = 1;
    selectedNews = false;
    newsList = [];
    this.getGoodsList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (selectedNews == true) {
      var that = this;
      // 显示加载图标  
      wx.showLoading({
        title: '玩命加载中',
      })
      // 页数+1  
      that.getGoodsList();

    } else {
      wx.hideLoading();
    }
  },

  renderCarte: function (params) {
    const that = this
    // let 
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})